// recycle 回收
import fetch from '../config/fetch'
import { getChannelCode } from '../config/utils'
import { API_PATH } from '../config/env'

/**
 * 默认地址
 */
export const getDefaultAddr = {
  code: '440100',
  city: '广州'
}

/**
 * 收货地址列表
 */
export const getDeliveryAddress = (token) => fetch(API_PATH + '/recycle/delivery-addresses', {
  token
}, 'POST')

/**
 * 我的收货地址更新
 */
export const deliveryAddressUpdate = (token, addressId, contact, mobile, provinceCodeUpdate, cityCodeUpdate, districtCodeUpdate, address, defaultAddr) => fetch(API_PATH + '/recycle/delivery-address-update', {
  token,
  id: addressId,
  contact,
  mobile,
  province_code: provinceCodeUpdate,
  city_code: cityCodeUpdate,
  district_code: districtCodeUpdate,
  address,
  default: defaultAddr
}, 'POST')

/**
 * 我的收货地址创建
 */
export const deliveryAddressCreate = (token, contact, mobile, provinceCodeUpdate, cityCodeUpdate, districtCodeUpdate, address, defaultAddr) => fetch(API_PATH + '/recycle/delivery-address-create', {
  token,
  contact,
  mobile,
  province_code: provinceCodeUpdate,
  city_code: cityCodeUpdate,
  district_code: districtCodeUpdate,
  address,
  default: defaultAddr
}, 'POST')

/**
 * 我的收货地址设置为默认
 */
export const deliveryAddressSetDefault = (token, addressId) => fetch(API_PATH + '/recycle/delivery-address-set-default', {
  token,
  id: addressId
}, 'POST')

/**
 * 我的收货地址删除
 */
export const deliveryAddressRemove = (token, addressId) => fetch(API_PATH + '/recycle/delivery-address-remove', {
  token,
  id: addressId
}, 'POST')

/**
 * 获取当前所在省
 */
export const provinceList = () => fetch(API_PATH + '/recycle/provinces', {}, 'POST')

/**
 * 获取当前所在市
 */
export const citiesList = (provinceCode) => fetch(API_PATH + '/recycle/cities', {
  province_code: provinceCode
}, 'POST')

/**
 * 获取当前所在区
 */
export const districtsList = (cityCode) => fetch(API_PATH + '/recycle/districts', {
  city_code: cityCode
}, 'POST')

/**
 * 下回收单
 */
export const order = (token, addressId, weight, remark, productId, serviceTime) => fetch(API_PATH + '/recycle/order', {
  channel_code: getChannelCode(),
  token,
  address_id: addressId,
  weight,
  remark,
  product_id: productId,
  service_time: serviceTime
}, 'POST')

/**
 * 下回收单
 */
export const availableDate = () => fetch(API_PATH + '/recycle/available-date', {}, 'POST')

